package com.tjetc.controller;

import com.tjetc.common.JsonResult;
import com.tjetc.entity.FoodContent;
import com.tjetc.entity.FoodRecord;
import com.tjetc.service.FoodContentService;
import com.tjetc.service.FoodRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("foodrecord")
public class FoodRecordController {
    @Autowired
    private FoodRecordService foodRecordService;

    @RequestMapping("detail/{recordId}")
    public JsonResult detail(@PathVariable("recordId") Long id) {
        return foodRecordService.findById(id);
    }
    @RequestMapping("pageelder")
    public JsonResult pageelder(@RequestParam(value = "name", required = false,defaultValue = "") String name,
                           @RequestParam(value = "pageNo",required = false,defaultValue = "1") Integer pageNo,
                           @RequestParam(value = "pageSize",required = false,defaultValue = "2") Integer pageSize) {
        return foodRecordService.findElderPage(name,pageNo,pageSize);
    }
    @RequestMapping("pagecaregiver")
    public JsonResult pagecaregiver(@RequestParam(value = "name", required = false,defaultValue = "") String name,
                           @RequestParam(value = "pageNo",required = false,defaultValue = "1") Integer pageNo,
                           @RequestParam(value = "pageSize",required = false,defaultValue = "2") Integer pageSize) {
        return foodRecordService.findCaregiverPage(name,pageNo,pageSize);
    }
    @RequestMapping("pagefoodcontent")
    public JsonResult pagefoodcontent(@RequestParam(value = "name", required = false,defaultValue = "") String name,
                           @RequestParam(value = "pageNo",required = false,defaultValue = "1") Integer pageNo,
                           @RequestParam(value = "pageSize",required = false,defaultValue = "2") Integer pageSize) {
        return foodRecordService.findFoodCntentPage(name,pageNo,pageSize);
    }
    @RequestMapping("delete/{recordId}")
    public JsonResult delete(@PathVariable("recordId") Long id) {
        return foodRecordService.deleteById(id);
    }
    //接收参数格式是json
    @RequestMapping("save")
    public JsonResult save(@RequestBody FoodRecord foodRecord){
        return foodRecordService.save(foodRecord);
    }
}
